// import com.alibaba.druid.sql.ast.SQLExpr;
// import com.alibaba.druid.sql.dialect.oracle.ast.OracleSQLObjectImpl;
// import com.alibaba.druid.sql.dialect.oracle.visitor.OracleASTVisitor;

// import java.util.ArrayList;
// import java.util.List;

#include "CycleClause.h"
#include "../../../../ast/SQLExpr.h"
#include "../../visitor/OracleASTVisitor.h"
#include "../../../../../utils/listTran.h"

CycleClause::CycleClause()
{
  aliases = std::make_shared<std::list<SQLExpr_ptr>>();
}
SQLExpr_ptr CycleClause::getMark()
{
  return mark;
}

void CycleClause::setMark(SQLExpr_ptr mark)
{
  if (mark != nullptr)
  {
    mark->setParent(SharedObject(CycleClause));
  }
  this->mark = mark;
}

SQLExpr_ptr CycleClause::getValue()
{
  return value;
}

void CycleClause::setValue(SQLExpr_ptr value)
{
  if (value != nullptr)
  {
    value->setParent(SharedObject(CycleClause));
  }
  this->value = value;
}

SQLExpr_ptr CycleClause::getDefaultValue()
{
  return defaultValue;
}

void CycleClause::setDefaultValue(SQLExpr_ptr defaultValue)
{
  if (defaultValue != nullptr)
  {
    defaultValue->setParent(SharedObject(CycleClause));
  }
  this->defaultValue = defaultValue;
}

SQLExpr_list_ptr CycleClause::getAliases()
{
  return aliases;
}

// @Override
void CycleClause::accept0(OracleASTVisitor_ptr visitor)
{
  if (visitor->visit(SharedObject(CycleClause)))
  {
    SQLObject_list_ptr tmp1 = ListTran::tran_class<SQLExpr, SQLObject>(aliases);
    acceptChild(visitor, tmp1);
    acceptChild(visitor, mark);
    acceptChild(visitor, value);
    acceptChild(visitor, defaultValue);
  }
  visitor->endVisit(SharedObject(CycleClause));
}

SQLObject_ptr CycleClause::clone()
{
  SQLObject_ptr clone_tmp = std::shared_ptr<CycleClause>(new CycleClause());
  std::shared_ptr<CycleClause> x = std::dynamic_pointer_cast<CycleClause>(clone_tmp);
  // CycleClause x = new CycleClause();

  for (SQLExpr_ptr alias : *aliases)
  {
    SQLExpr_ptr alias2 = std::dynamic_pointer_cast<SQLExpr>(alias->clone());
    alias2->setParent(x);
    x->aliases->push_back(alias2);
  }

  if (mark != nullptr)
  {
    setMark(std::dynamic_pointer_cast<SQLExpr>(mark->clone()));
  }

  if (value != nullptr)
  {
    setValue(std::dynamic_pointer_cast<SQLExpr>(value->clone()));
  }

  if (defaultValue != nullptr)
  {
    setDefaultValue(std::dynamic_pointer_cast<SQLExpr>(defaultValue->clone()));
  }

  return x;
}
